<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Test dojox.grid.Grid Editing</title>
	<style type="text/css">
		@import "../resources/Grid.css";
		@import "../resources/tundraGrid.css";
		@import "../../../dojo/resources/dojo.css";
		@import "../../../dijit/themes/tundra/tundra.css";
		@import "../../../dijit/themes/tundra/tundra_rtl.css";
		@import "../../../dijit/tests/css/dijitTests.css";
		#controls button {
			margin-left: 10px;
		}
		#grid {
			width: 850px;
			height: 350px;
			border: 1px solid silver;
		}
		</style>
	<script type="text/javascript" src="../../../dojo/dojo.js" 
		data-dojo-config="isDebug: true, parseOnLoad: true"></script>

	<script type="text/javascript">
		dojo.require("dijit.dijit");
		dojo.require("dojox.grid.DataGrid");
		dojo.require("dojox.grid.cells.dijit");
		dojo.require("dojo.data.ItemFileWriteStore");
		dojo.require("dojo.parser");
	</script>
	<script type="text/javascript" src="support/test_data_date.js"></script>
	<script type="text/javascript">
		// ==========================================================================
		// Custom formatters
		// ==========================================================================
		formatCurrency = function(inDatum){
			return isNaN(inDatum) ? '...' : dojo.currency.format(inDatum, this.constraint);
		}
		formatDate = function(inDatum){
			return dojo.date.locale.format(new Date(inDatum), this.constraint);
		}
		// ==========================================================================
		// Grid structure
		// ==========================================================================
		statusCell = {
			field: 'col3', name: 'Status', 
			styles: 'text-align: center;', 
			type: dojox.grid.cells.Select, 
			options: [ "new", "read", "replied" ]
		};

		gridLayout = [{
			defaultCell: { width: 8, editable: true, type: dojox.grid.cells._Widget, styles: 'text-align: right;'  },
			rows: [
				{ name: 'Id', field: 'id', editable: false /* Can't edit ID's of dojo.data items */ },
				{ name: 'Date', field: 'col8', width: 10,
					type: dojox.grid.cells.DateTextBox,
					formatter: formatDate, 
					constraint: {formatLength: 'long', selector: "date"}},
				{ name: 'Priority', styles: 'text-align: center;', field: 'col1', 
					type: dojox.grid.cells.ComboBox, 
					options: ["normal", "note", "important"], width: 10},
				{ name: 'Mark', field: 'col2', width: 3, styles: 'text-align: center;', 
					type: dojox.grid.cells.CheckBox},
				statusCell,
				{ name: 'Message', field: 'col4', styles: '', width: 10, 
					type: dojox.grid.cells.Editor, editorToolbar: true },
				{ name: 'Amount', field: 'col5', formatter: formatCurrency, constraint: {currency: 'EUR'}, 
					widgetClass: dijit.form.CurrencyTextBox },
				{ name: 'Amount', field: 'col5', formatter: formatCurrency, constraint: {currency: 'EUR'}, 
					widgetClass: dijit.form.HorizontalSlider, width: 10}
			]
		}];
		// ==========================================================================
		// UI Action
		// ==========================================================================
		addRow = function(){
			test_store.newItem({
				id: grid.rowCount,
				col1: 'normal',
				col2: false,
				col3: 'new',
				col4: 'Now is the time for all good men to come to the aid of their party.',
				col5: 99.99,
				col6: 9.99,
				col7: false,
				col8: new Date()
			});
		}
	</script>
</head>
<body class="tundra">
	<h1>dojox.grid.DataGrid Basic Editing test</h1>
	<br />
	<div id="controls">
		<button onclick="grid.render()">Refresh</button>
		<button onclick="grid.edit.focusEditor()">Focus Editor</button>
		<button onclick="grid.focus.next()">Next Focus</button>
		<button onclick="addRow()">Add Row</button>
		<button onclick="grid.removeSelectedRows()">Remove</button>
		<button onclick="grid.edit.apply()">Apply</button>
		<button onclick="grid.edit.cancel()">Cancel</button>
		<button onclick="grid.singleClickEdit = !grid.singleClickEdit">Toggle singleClickEdit</button>
	</div>
	<br />
	<div id="grid" data-dojo-id="grid" dojoType="dojox.grid.DataGrid" store="test_store" rowSelector="20px" structure="gridLayout" escapeHTMLInData="false"></div>
	<br />
	<div id="rowCount"></div>
</body>
</html>
